package cn.edu.scau.cmi.lishuoxin.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/*
 * C3P0的抽取工具类，把创建连接池和获取连接都抽取出来，写成一个类
 */
public class C3P0Utils {
	//使用命名配置
	private static ComboPooledDataSource dataSource = new ComboPooledDataSource("cmi");
	
	/*
	 * 获取数据源（连接池）
	 */
	public static DataSource getDataSource() {
		return dataSource;
	}
	/*
	 * 获得连接
	 */
	public static Connection getConnection() {
		try {
			return dataSource.getConnection();
		} catch (SQLException e) {
			throw new RuntimeException(e);  //抛出新异常
		}
	}
}
